package cn.maxwell.org.controller;

import cn.maxwell.basic.util.JsonResult;
import cn.maxwell.basic.util.LoginContext;
import cn.maxwell.org.domain.ShopLog;
import cn.maxwell.org.service.IShopLogService;
import cn.maxwell.user.domain.Logininfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@RequestMapping("/audit")
public class ShopLogController {
    @Autowired
    private IShopLogService logService;

    /**
     * 审批通过
     * @param shopLog
     * @return
     */
    @RequestMapping("/pass")
    public JsonResult pass(@RequestBody ShopLog shopLog, HttpServletRequest request){
        Logininfo logininfo = (Logininfo) LoginContext.getLoginUser(request);
        Long logininfo_id = logininfo.getId();
        try {
            logService.pass(shopLog,logininfo_id);
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("审核未通过");
        }
    }

    /**
     * 审批不予通过（驳回）
     * @param shopLog
     * @return
     */
    @RequestMapping("/reject")
    public JsonResult reject(@RequestBody ShopLog shopLog,HttpServletRequest request){
        Logininfo logininfo = (Logininfo) LoginContext.getLoginUser(request);
        Long logininfo_id = logininfo.getId();
        try {
            logService.reject(shopLog,logininfo_id);
            return JsonResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return JsonResult.me().setMsg("驳回失败");
        }
    }
}
